import tkinter as tk

class MyWindow():
    def __init__(self,app):
        self.app = app
        self.app.title("Hello tkinter!")

        self.content = tk.StringVar()
        # 如果变量变化了,那么就触发该trace中绑定的函数
        self.content.trace("w",lambda name,index,mode,content=
        self.content: self.on_entry_change(self.content.get()))

        self.entry = tk.Entry(self.app,width=20,textvariable=self.content)
        self.entry.pack()

    def on_entry_change(self,sv):
        print(sv)

if __name__ == '__main__':
    app = tk.Tk()
    window = MyWindow(app)
    app.mainloop()